package nl.unimaas.micc.umsnooker.gameflow;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.jme.math.Vector3f;

import nl.unimaas.micc.umsnooker.domain.BilliardBall;
import nl.unimaas.micc.umsnooker.domain.Player;
import nl.unimaas.micc.umsnooker.domain.Table;
import nl.unimaas.micc.umsnooker.domain.BilliardBall.Type;

public class GameState
{
	public static final Set<BilliardBall.Type> redBalls;
	public static final Set<BilliardBall.Type> colourBalls;

	static
	{
		redBalls = new HashSet<BilliardBall.Type>();
		colourBalls = new HashSet<BilliardBall.Type>();

		redBalls.add(Type.RED);
		colourBalls.add(Type.BLUE);
		colourBalls.add(Type.BLACK);
		colourBalls.add(Type.BROWN);
		colourBalls.add(Type.GREEN);
		colourBalls.add(Type.PINK);
		colourBalls.add(Type.YELLOW);
	}
	
	private Set<BilliardBall.Type> onBalls;
	private List<Player> players;
	private Set<BilliardBall> balls;
	private BilliardBall cueBall;
	private Table table;
	private Player currentPlayer;
	private GamePhase currentPhase;
	
	public GameState()
	{
		balls = new HashSet<BilliardBall>();
	}
	
	
	public boolean isSpotFree(Vector3f spot)
	{
		for (BilliardBall ball : balls)
		{
			if (ball.getPosition().distance(spot) <= ball.getRadius() * 2)
			{
				return false;
			}
		}
		return true;
	}
	
	
	public Set<BilliardBall.Type> getOnBalls()
	{
		return onBalls;
	}

	public void setOnBalls(Set<BilliardBall.Type> onBalls)
	{
		this.onBalls = onBalls;
	}

	public void addBall(BilliardBall ball)
	{
		balls.add(ball);
	}
	
	
	public BilliardBall getCueBall()
	{
		return cueBall;
	}
	
	public void setCueBall(BilliardBall ball)
	{
		this.cueBall = ball;
	}
	
	public List<Player> getPlayers()
	{
		return players;
	}
	public void setPlayers(List<Player> players)
	{
		this.players = players;
	}
	public Set<BilliardBall> getBalls()
	{
		return balls;
	}
	public void setBalls(Set<BilliardBall> balls)
	{
		this.balls = balls;
	}
	public Table getTable()
	{
		return table;
	}
	public void setTable(Table table)
	{
		this.table = table;
	}
	public Player getCurrentPlayer()
	{
		return currentPlayer;
	}
	public void setCurrentPlayer(Player currentPlayer)
	{
		this.currentPlayer = currentPlayer;
	}
	public GamePhase getCurrentPhase()
	{
		return currentPhase;
	}
	public void setCurrentPhase(GamePhase currentPhase)
	{
		this.currentPhase = currentPhase;
	}
	
	
}
